home *** CD-ROM | disk | FTP | other *** search
/ The Utilities Experience / The Utilities Experience - Volume 1.iso / software / graphics / n-z / raystorexa / examples / worldanim.cpp < prev    next >
Text File  |  1995-10-18  |  5KB  |  208 lines

  1. /***************
  2.  * NAME:          worldanim.cpp
  3.  * VERSION:       1.0 10.08.1995
  4.  * DESCRIPTION:   Example program for RayStorm
  5.  *                        this program has been compiled with Maxon C++ 3.0
  6.  *    AUTHORS:            Andreas Heumann, Mike Hesser
  7.  * BUGS:          none
  8.  * TO DO:         
  9.  * HISTORY:       DATE        NAME    COMMENT
  10.  *                        10.08.95    ah        first release
  11.  ***************/
  12.  
  13. #include <exec/memory.h>
  14. #include <rexx/storage.h>
  15. #include <rexx/rxslib.h>
  16. #include <exec/types.h>
  17.  
  18. #include <pragma/exec_lib.h>
  19. #include <pragma/rexxsyslib_lib.h>
  20.  
  21. #include <fstream.h>
  22. #include <stdlib.h>
  23. #include <string.h>
  24. #include <stdio.h>
  25. #include <math.h>
  26.  
  27. struct Library *RexxSysBase = NULL;
  28. static struct MsgPort *HostPort;
  29. static struct MsgPort *ReplyPort = NULL;
  30.  
  31. static int msgs = 0;        // remaining messages
  32.  
  33. /*************
  34.  * FUNCTION:        cleanup
  35.  * VERSION:            1.0 08.05.1995
  36.  * DESCRIPTION:    close libs ...
  37.  * INPUT:            none
  38.  * OUTPUT:            none
  39.  * HISTORY:       DATE        NAME        COMMENT
  40.  *                        08.05.95    ah            first release
  41.  *************/
  42. void cleanup()
  43. {
  44.     struct RexxMsg *RexxMessage;
  45.  
  46.     if(ReplyPort)
  47.     {
  48.         // free messages
  49.         while(msgs)
  50.         {
  51.             // Wait for message
  52.             WaitPort(ReplyPort);
  53.             // get messages
  54.             while(RexxMessage = (struct RexxMsg*)GetMsg(ReplyPort))
  55.             {
  56.                 // Remove Rexx message
  57.                 ClearRexxMsg(RexxMessage,1);
  58.                 DeleteRexxMsg(RexxMessage);
  59.                 msgs--;
  60.             }
  61.         }
  62.         // Free reply port signal bit
  63.         FreeSignal(ReplyPort->mp_SigBit);
  64.         // Free the replyport itself
  65.         FreeMem(ReplyPort,sizeof(struct MsgPort));
  66.     }
  67.     if (RexxSysBase)
  68.         CloseLibrary(RexxSysBase);
  69.     exit(0);
  70. }
  71.  
  72. /*************
  73.  * FUNCTION:        SendRexxMsg
  74.  * VERSION:            1.0 08.05.1995
  75.  * DESCRIPTION:    Sends a single command to Rexx host
  76.  * INPUT:            HostPort        pointer to host message port
  77.  *                        SingleMsg    message to send
  78.  * OUTPUT:            none
  79.  * HISTORY:       DATE        NAME        COMMENT
  80.  *                        08.05.95    ah            first release
  81.  *************/
  82. void SendRexxMsg(struct MsgPort *HostPort, char *SingleMsg)
  83. {
  84.     struct RexxMsg *RexxMessage;
  85.  
  86.     // free previous messages
  87.     while(RexxMessage = (struct RexxMsg*)GetMsg(ReplyPort))
  88.     {
  89.         // Remove Rexx message
  90.         if(RexxMessage->rm_Result1)
  91.            cout << RexxMessage->rm_Args[0] << "-> Error: " << RexxMessage->rm_Result1 << "\n";
  92.         ClearRexxMsg(RexxMessage,1);
  93.         DeleteRexxMsg(RexxMessage);
  94.         msgs--;
  95.     }
  96.  
  97.     // Valid pointers given?
  98.     if(HostPort && SingleMsg)
  99.     {
  100.         // Create a Rexx message
  101.         RexxMessage = (struct RexxMsg *)CreateRexxMsg(ReplyPort,"",NULL);
  102.         if(RexxMessage)
  103.         {
  104.             RexxMessage->rm_Args[0] = CreateArgstring(SingleMsg, strlen(SingleMsg));
  105.             RexxMessage->rm_Action = RXFF_RESULT;
  106.  
  107.             // Send packet
  108.             PutMsg(HostPort,(struct Message *)RexxMessage);
  109.             msgs++;
  110.             WaitPort(ReplyPort);
  111.             RexxMessage = (struct RexxMsg*)GetMsg(ReplyPort);
  112.             // Remove Rexx message
  113.             if(RexxMessage->rm_Result1)
  114.                cout << RexxMessage->rm_Args[0] << "-> Error: " << RexxMessage->rm_Result1 << "\n";
  115.             ClearRexxMsg(RexxMessage,1);
  116.             DeleteRexxMsg(RexxMessage);
  117.             msgs--;
  118.         }
  119.     }
  120. }
  121.  
  122. /*************
  123.  * FUNCTION:        Init
  124.  * VERSION:            1.0 08.05.1995
  125.  * DESCRIPTION:    Open libs, init ports
  126.  * INPUT:            none
  127.  * OUTPUT:            none
  128.  * HISTORY:       DATE        NAME        COMMENT
  129.  *                        08.05.95    ah            first release
  130.  *************/
  131. void Init()
  132. {
  133.     // is raystrom already active ?
  134.     HostPort = (struct MsgPort *)FindPort("RAYSTORM");
  135.     if(!HostPort)
  136.     {
  137.         cout << "Raystorm is not running please start it\n";
  138.         cleanup();
  139.     }
  140.     // Allocate a reply port
  141.     ReplyPort = (struct MsgPort *)AllocMem(sizeof(struct MsgPort),MEMF_PUBLIC | MEMF_CLEAR);
  142.     if(ReplyPort)
  143.     {
  144.         ReplyPort->mp_SigBit = AllocSignal(-1);
  145.         if(ReplyPort->mp_SigBit != -1)
  146.         {
  147.             ReplyPort->mp_Node.ln_Type    = NT_MSGPORT;
  148.             ReplyPort->mp_Flags            = PA_SIGNAL;
  149.             ReplyPort->mp_SigTask        = FindTask(NULL);
  150.  
  151.             ReplyPort->mp_MsgList.lh_Head = (struct Node *)&ReplyPort->mp_MsgList.lh_Tail;
  152.             ReplyPort->mp_MsgList.lh_Tail = 0;
  153.             ReplyPort->mp_MsgList.lh_TailPred = (struct Node *)&ReplyPort->mp_MsgList.lh_Head;
  154.         }
  155.     }
  156.  
  157.     // Open rexxsyslib library.
  158.     RexxSysBase = OpenLibrary("rexxsyslib.library",0L);
  159.     if (!RexxSysBase)
  160.     {
  161.         cout << "Can't open rexxsyslib.library\n";
  162.         cleanup();
  163.     }
  164. }
  165.  
  166. void main(int argc, char *argv[])
  167. {
  168.     float f;
  169.     int i, pics;
  170.     char buffer[256];
  171.  
  172.     // Parse arguments
  173.     if(argc != 2)
  174.     {
  175.         cout << "Worldanim V1.0 1995 by Andreas Heumann\n";
  176.         cout << "Usage: worldanim picnum\n";
  177.         cout << "   picnum - amount of pictures to create\n";
  178.         cleanup();
  179.     }
  180.     sscanf(argv[1],"%d",&pics);
  181.     if(pics<2)
  182.     {
  183.         cout << "I need at least two pictures to create.\n";
  184.         cleanup();
  185.     }
  186.  
  187.     Init();
  188.  
  189.     i=1;
  190.     for(f=0; f<360; f+=360/pics)
  191.     {
  192.         SendRexxMsg(HostPort, "SETSCREEN 160 128");
  193.         SendRexxMsg(HostPort, "SETWORLD [0,0,0] [100,100,100]");
  194.         SendRexxMsg(HostPort, "SETCAMERA <0,0,4> <0,0,0> <0,1,0> 56.25 45");
  195.         SendRexxMsg(HostPort, "POINTLIGHT <5,5,10>");
  196.         SendRexxMsg(HostPort, "NEWSURFACE EARTH");
  197.         sprintf(buffer, "BRUSH /brushes/earth.iff COLOR WRAPXY <0,0,0> <0,%d,0> <.1,.1,.1>", int(f));
  198.         SendRexxMsg(HostPort, buffer);
  199.         SendRexxMsg(HostPort, "SPHERE EARTH <0,0,0> 1");
  200.         SendRexxMsg(HostPort, "STARTRENDER QUICK");
  201.         sprintf(buffer, "SAVEPIC pics/world.%04d", i);
  202.         SendRexxMsg(HostPort, buffer);
  203.         SendRexxMsg(HostPort, "CLEANUP");
  204.         i++;
  205.     }
  206.  
  207.     cleanup();
  208. }